import 'package:get/get.dart';
import 'package:flutter/material.dart';
import 'package:xmshop/app/services/screebAdapter.dart';
import 'package:xmshop/app/widget/passButton.dart';
import '../controllers/pay_controller.dart';

class PayView extends GetView<PayController> {
  const PayView({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color.fromRGBO(247, 247, 247, 1),
      appBar: AppBar(
        backgroundColor: Colors.white,
        title: const Text('支付页'),
      ),
      body: ListView(
        padding: EdgeInsets.all(ScreenAdapter.width(40)),
        children: [
          ListView.builder(
            shrinkWrap: true,
            physics: const NeverScrollableScrollPhysics(),
            itemCount: controller.payList.length,
            itemBuilder: (BuildContext context, int index) {
              return Obx(() => InkWell(
                    onTap: () {
                      controller.changePayList(
                          index, controller.payList[index]['id']);
                    },
                    child: Container(
                      decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.circular(10)),
                      padding: EdgeInsets.all(ScreenAdapter.width(40)),
                      margin: EdgeInsets.only(top: ScreenAdapter.width(40)),
                      child: ListTile(
                        leading:
                            Image.network(controller.payList[index]['image']),
                        title: Text(controller.payList[index]['title']),
                        trailing: controller.payList[index]['checked'] == true
                            ? const Icon(Icons.check)
                            : const Text(''),
                      ),
                    ),
                  ));
            },
          ),
          Container(
            margin: EdgeInsets.only(top: ScreenAdapter.width(80)),
            child: PassButton(
                text: "支付",
                onPressed: () {
                  controller.pay();
                }),
          )
        ],
      ),
    );
  }
}
